﻿/*******************************************
 * 
 *      个性化窗体基类
 * 
 * 
 * *****************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NF_Base;
using System.Runtime.InteropServices;
using NF_Web.Event;

namespace NF_Web
{
    public partial class FrmObject : Form
    {
        public FrmObject()
        {
            InitializeComponent();
            ActiveEvent.MinFormEvent +=ActiveEvent_MinFormEvent; 
        }
                  
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002; 

        /// <summary>
        /// 标题
        /// </summary>
        public string Title = "捉影微影院运营管理平台";

        /// <summary>
        /// 单机任务栏显示隐藏
        /// </summary>
        protected override CreateParams CreateParams
        {
            get
            {
                const int WS_MINIMIZEBOX = 0x00020000;  // Winuser.h中定义   
                CreateParams cp = base.CreateParams;
                cp.Style = cp.Style | WS_MINIMIZEBOX;   // 允许最小化操作   
                return cp;
            }
        }
              
        void ActiveEvent_MinFormEvent()
        {
            this.WindowState = FormWindowState.Minimized;
        }

        /// <summary>
        /// LODE
        /// </summary>
        private void frmET_Object_Load(object sender, EventArgs e)
        {
            this.lblTitle.Text = Title;
        }
                   
        /// <summary>
        /// 进入最小化按钮
        /// </summary>
        private void pnl_MouseEnter(object sender, EventArgs e)
        {
            Panel p = sender as Panel;
            if (p.Tag.ToString() == "关闭")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.icon_close_hover;
            }
            else if (p.Tag.ToString() == "最大化")
            {
                if (this.WindowState != FormWindowState.Maximized)
                {
                   //最大化图标
                    p.BackgroundImage = global::NF_Web.Properties.Resources.icon_bigger_hover;
                }
                else
                {
                   //最小化图标
                    p.BackgroundImage = global::NF_Web.Properties.Resources.icon_small_hover;
                }
            }
            else if (p.Tag.ToString() == "最小化")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.icon_min_hover;
            }
        }
                   
        /// <summary>
        /// 离开关闭按钮
        /// </summary>
        private void pnl_MouseLeave(object sender, EventArgs e)
        {
            Panel p = sender as Panel;
            if (p.Tag.ToString() == "关闭")
            {                      
                p.BackgroundImage = global::NF_Web.Properties.Resources.Close_w;
            }
            else if (p.Tag.ToString() == "最大化")
            {
                if (this.WindowState != FormWindowState.Maximized)
                {
                    //最大化图标（默认）
                    p.BackgroundImage = global::NF_Web.Properties.Resources.Max_w;
                }
                else
                {
                    //最小化图标（默认）
                    p.BackgroundImage = global::NF_Web.Properties.Resources.icon_small_default;
                }
            }
            else if (p.Tag.ToString() == "最小化")
            {
                p.BackgroundImage = global::NF_Web.Properties.Resources.Min_w;
            }
        }
                   
        /// <summary>
        /// 关闭/最大化/最小化 单击事件
        /// </summary>
        private void pnl_MouseClick(object sender, MouseEventArgs e)
        {
           
            Panel p = sender as Panel;
            if (p.Tag.ToString() == "关闭")
            {
                this.Close();
            }
            else if (p.Tag.ToString() == "最大化")
            {
                if (this.WindowState != FormWindowState.Maximized)
                    this.WindowState = FormWindowState.Maximized;
                else
                    this.WindowState = FormWindowState.Normal;
            }
            else if (p.Tag.ToString() == "最小化")
            {
                this.WindowState = FormWindowState.Minimized;
            }

        }

        /// <summary>
        /// 拖动
        /// </summary>
        private void pnlTop_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }

        private void FrmObject_SizeChanged(object sender, EventArgs e)
        {
            int x = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
            int y = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
            if (this.WindowState == FormWindowState.Normal)
            {
                this.Left = x;
                this.Top = y;
            }
            //if (this.WindowState == FormWindowState.Maximized && BaseClass.MinxFrm != null)
            //{
            //    BaseClass.MinxFrm.Show();
            //}
        }
    }
}
